package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"gorm.io/gorm"
	"home-manage/homerpc/homerpc"
	"home-manage/homerpc/internal/svc"
	"home-manage/model"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *homerpc.PrefectRequest) (*homerpc.PrefectResponse, error) {
	// todo: add your logic here and delete this line

	var user model.User
	user = model.User{
		Model: gorm.Model{
			ID: uint(in.UserId),
		},
		Img:      in.Img,
		Tel:      in.Tel,
		Password: in.Password,
		Username: in.Username,
	}
	model.DB.Debug().Updates(&user)

	return &homerpc.PrefectResponse{
		UserId: int64(user.ID),
	}, nil
}
